﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Avatar.Model;
using AvatarHelper;
using System.Data;

[Serializable]
public class JobSimple
{
    string _companyName;
    public string CompanyName
    {
        get
        {
            return _companyName;
        }
        set
        {
            _companyName = value;
        }
    }
    string _user;
    public string User
    {
        get
        {
            return _user;
        }
        set
        {
            _user = value;
        }
    }
    DateTime _updateTime;
    public DateTime UpdateTime
    {
        get
        {
            return _updateTime;
        }
        set
        {
            _updateTime = value;
        }
    }
}
public partial class UserControl_NewCompany : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        using (var _adc = DBHelper.GetDataContext())
        {
            if (Cache["jobs"] == null)
            {
                var _jobs = new List<JobSimple>();
                var _j = _adc.CompanyInformation.Where(i => i.CompanyName.Length > 5 && i.Description.Length > 20 && i.Job.Count > 0).Select(i => new { CompanyName = i.CompanyName, User = i.User, UpdateTime = i.UpdateTime }).OrderByDescending(i => i.UpdateTime).Take(102);
                foreach (var _jj in _j)
                {
                    var _jjj = new JobSimple();
                    _jjj.CompanyName = _jj.CompanyName;
                    _jjj.UpdateTime = _jj.UpdateTime == null ? DateTime.MinValue : (DateTime)_jj.UpdateTime;
                    _jjj.User = _jj.User;

                    _jobs.Add(_jjj);
                }
                Cache.Insert("jobs", _jobs, null, DateTime.Now.AddMinutes(30), TimeSpan.Zero);
            }

            ListView1.DataSource = (List<JobSimple>)Cache["jobs"];
            ListView1.DataBind();
        }
    }
    //显示new图标
    public string imgnew(DateTime _imgnew)
    {

        string _str = null;
        if (_imgnew.ToString("yyyyMMdd") == DateTime.Now.ToString("yyyyMMdd"))
        {
            _str = "<div class=\"newgif\"></div>";
        }
        return _str;
    }
    // 普通企业子控件显示内容
    protected void Companyzp_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.FindControl("Companyzp_Child") != null)
        {
            var drv = (CompanyInformation)e.Item.DataItem;
            string _pid = drv.CompanyName;

            Repeater rp = (Repeater)e.Item.FindControl("Companyzp_Child");
            rp.DataSource = DBHelper.GetAll<Job>("获取职位列表失败：");
            rp.DataBind();
        }
    }
    protected string GetJobs(string _company)
    {
        string _jobName = string.Empty;
        var _jobs = DBHelper.GetAll<Job>(j => j.PublisherUser == _company, 2, "获取诸位列表出错");

        foreach (var _job in _jobs)
        {
            _jobName = _jobName + "<a href='./job.aspx?id=" + _job.ID + "' class='font_show_blues' target='_blank'>" + _job.Title + "</a>&nbsp;";
        }
        if (!string.IsNullOrEmpty(_jobName)) _jobName = "<br>&nbsp;&nbsp;" + _jobName;

        return _jobName;
    }
}
